package com.scs.application.modules.sys.adapter;

import com.scs.application.modules.sys.properties.SystemProperties;
import com.scs.application.modules.sys.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description:流程类适配器
 */
@Component
public class FlowAdapter {
    @Autowired
    private SystemProperties systemProperties;

    private List<FlowService> flowServices;

    private List<FlowButtonService> flowButtonServices;

    private List<FlowNodeService> flowNodeServices;

    @Autowired
    @Lazy
    private void setFlowServices(List<FlowService> flowServices) {
        this.flowServices = flowServices;
    }

    @Autowired
    @Lazy
    private void setFlowButtonServices(List<FlowButtonService> flowButtonServices) {
        this.flowButtonServices = flowButtonServices;
    }

    @Autowired
    @Lazy
    private void setFlowNodeServices(List<FlowNodeService> flowNodeServices) {
        this.flowNodeServices = flowNodeServices;
    }

    /**
     * 获取当前项目的FlowService实现类
     * @return
     */
    public FlowService getFlowService() {
        FlowService flowService = null;
        for(FlowService flowService1 : flowServices) {
            if (flowService1.isSupport(systemProperties.getFlagProject())) {
                flowService = flowService1;
                break;
            }
        }
        return flowService;
    }

    /**
     * 获取当前项目的FlowNodeService实现类
     * @return
     */
    public FlowNodeService getFlowNodeService() {
        FlowNodeService flowNodeService = null;
        for(FlowNodeService flowService : flowNodeServices) {
            if (flowService.isSupport(systemProperties.getFlagProject())) {
                flowNodeService = flowService;
                break;
            }
        }
        return flowNodeService;
    }

    /**
     * 获取当前项目的FlowButtonService实现类
     * @return
     */
    public FlowButtonService getFlowButtonService() {
        FlowButtonService flowButtonService = null;
        for(FlowButtonService flowService : flowButtonServices) {
            if (flowService.isSupport(systemProperties.getFlagProject())) {
                flowButtonService = flowService;
                break;
            }
        }
        return flowButtonService;
    }

    /**
     * 获取当前项目的FlowService实现类
     * @return
     */
    public FlowService getFlowService(Boolean flagProject) {
        FlowService flowService = null;
        for(FlowService flowService1 : flowServices) {
            if (flowService1.isSupport(flagProject)) {
                flowService = flowService1;
                break;
            }
        }
        return flowService;
    }

    /**
     * 获取当前项目的FlowNodeService实现类
     * @return
     */
    public FlowNodeService getFlowNodeService(Boolean flagProject) {
        FlowNodeService flowNodeService = null;
        for(FlowNodeService flowService : flowNodeServices) {
            if (flowService.isSupport(flagProject)) {
                flowNodeService = flowService;
                break;
            }
        }
        return flowNodeService;
    }

    /**
     * 获取当前项目的FlowButtonService实现类
     * @return
     */
    public FlowButtonService getFlowButtonService(Boolean flagProject) {
        FlowButtonService flowButtonService = null;
        for(FlowButtonService flowService : flowButtonServices) {
            if (flowService.isSupport(flagProject)) {
                flowButtonService = flowService;
                break;
            }
        }
        return flowButtonService;
    }
}
